package com.sam4cloud.auth.utils;

import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

import java.nio.charset.StandardCharsets;

/**
 * @Author: Sam
 * @Date: 2022-11-25 14:13
 * @Description: 加密工具类
 */
public class EncryptUtils {

    public static final String AES_KEY = "GEZa13sSIJ90_a2";

    /**
     * AES解密
     *
     * @param data 需要解密的数据
     * @return
     */
    public static String aesDecrypt(String data) {
        SymmetricCrypto symmetricCrypto = new SymmetricCrypto(SymmetricAlgorithm.AES, AES_KEY.getBytes(StandardCharsets.UTF_8));
        return symmetricCrypto.decryptStr(data);
    }

    /**
     * AES解密
     *
     * @param data   需要解密的数据
     * @param aesKey 密钥
     * @return
     */
    public static String aesDecrypt(String data, String aesKey) {
        SymmetricCrypto symmetricCrypto = new SymmetricCrypto(SymmetricAlgorithm.AES, aesKey.getBytes(StandardCharsets.UTF_8));
        return symmetricCrypto.decryptStr(data);
    }

    /**
     * AES加密
     *
     * @param data 需要加密的数据
     * @return
     */
    public static String aesEncrypt(String data) {
        SymmetricCrypto symmetricCrypto = new SymmetricCrypto(SymmetricAlgorithm.AES, AES_KEY.getBytes(StandardCharsets.UTF_8));
        return symmetricCrypto.encryptBase64(data);
    }

    /**
     * AES加密
     *
     * @param data   需要加密的数据
     * @param aesKey 密钥
     * @return
     */
    public static String aesEncrypt(String data, String aesKey) {
        SymmetricCrypto symmetricCrypto = new SymmetricCrypto(SymmetricAlgorithm.AES, aesKey.getBytes(StandardCharsets.UTF_8));
        return symmetricCrypto.encryptBase64(data);
    }
}
